package org.geektimes.projects.user.management;

import javax.management.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 雪蓑
 * @Date: 2021/3/16 下午9:11
 * @Discription //todo
 */
public class UserMXBean implements DynamicMBean {

    private Map<String,Object> attributes = new HashMap<>();

    @Override
    public Object getAttribute(String attribute) throws AttributeNotFoundException {
        if(!attributes.containsKey(attribute)){
            throw new AttributeNotFoundException("...");
        }
        return attributes.get(attribute);
    }

    @Override
    public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
        attributes.put(attribute.getName(),attribute.getValue());
    }

    @Override
    public AttributeList getAttributes(String[] attributes) {
        AttributeList attributeList = new AttributeList();
        for(String attribute : attributes){
            Object attributeValue = null;
            try {
                attributeValue = getAttribute(attribute);
            } catch (AttributeNotFoundException e) {
            }
            attributeList.add(new Attribute(attribute, attributeValue));
        }
        return attributeList;
    }

    @Override
    public AttributeList setAttributes(AttributeList attributes) {
        return null;
    }

    @Override
    public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException {
        return null;
    }

    @Override
    public MBeanInfo getMBeanInfo() {
        return null;
    }
}
